package io.geekidea.springbootplus.system.controller;

import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.system.entity.SysOrderDetails;
import io.geekidea.springbootplus.system.entity.SysProductAttribute;
import io.geekidea.springbootplus.system.service.SysOrderDetailsService;
import io.geekidea.springbootplus.system.vo.SysMemberQueryVo;
import io.geekidea.springbootplus.system.vo.SysOrderDetailsQueryVo;
import io.geekidea.springbootplus.system.vo.SysOrderQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

@Slf4j
@Controller
@RequestMapping("/sysOrderDetails")
@Module("system")
@Api(value = "订单详情API", tags = {"订单详情管理"})

public class SysOrderDetailsController extends BaseController {
    @Resource
    private SysOrderDetailsService sysOrderDetailsService;

    @GetMapping("/orderDetailsId/{id}")
    @OperationLog(name = "查询商品信息详情", type = OperationLogType.INFO)
    @ApiOperation(value = "查询商品信息详情",   response =SysOrderDetailsQueryVo.class)
    public ApiResult getSysOrderDetailsById(@PathVariable("id") Integer id) throws Exception {
        SysOrderDetailsQueryVo orderDetails = sysOrderDetailsService.selectOrderDetailsById(id);
        if (orderDetails != null){
            return ApiResult.ok(orderDetails);
        }else {
            return ApiResult.fail(500,"该id不存在或被删除");
        }
    }

    @GetMapping("/orderDetailsOrderId/{orderId}")
    @OperationLog(name="查询订单商品信息",type= OperationLogType.LIST)
    @ApiOperation(value="查询订单商品信息",response = SysOrderDetailsQueryVo.class)
    public ApiResult<List<SysOrderDetailsQueryVo>> selectOrderDetailsByOrderId(@PathVariable(value ="orderId")Long orderId)throws Exception{
        List<SysOrderDetailsQueryVo> orderDetailsQueryVos= sysOrderDetailsService.selectOrderDetailsByOrderId(orderId);
        return ApiResult.ok(orderDetailsQueryVos);
    }

    @PostMapping("/orderDetails/delete/{id}")
    @OperationLog(name = "删除订单详情", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除订单详情", response = ApiResult.class)
    public ApiResult<Boolean> deleteOrderDetails(@PathVariable("id")Long id) throws Exception {
        boolean flag = sysOrderDetailsService.deleteOrderDetails(id);
        return ApiResult.result(flag);
    }

    @GetMapping("/orderDetailsProductName/{productName}")
    @OperationLog(name="根据商品名查询信息",type= OperationLogType.LIST)
    @ApiOperation(value="根据商品名查询信息",response = SysOrderDetailsQueryVo.class)
    public ApiResult<List<SysOrderDetailsQueryVo>> selectOrderDetailsByOrderId(@PathVariable(value ="productName")String productName)throws Exception{
        List<SysOrderDetailsQueryVo> orderDetailsQueryVos= sysOrderDetailsService.selectOrderDetailsByProductName(productName);
        return ApiResult.ok(orderDetailsQueryVos);
    }

    @GetMapping("/orderDetailsProductPrice/{productPrice}")
    @OperationLog(name = "价格查询商品信息详情", type = OperationLogType.LIST)
    @ApiOperation(value = "价格查询商品信息详情",   response =SysOrderDetailsQueryVo.class)
    public  ApiResult<List<SysOrderDetailsQueryVo>>  getSysOrderDetailsProductPrice(@PathVariable("productPrice") BigDecimal productPrice) throws Exception {
        List<SysOrderDetailsQueryVo> orderDetails = sysOrderDetailsService.selectProductNameByProductPrice(productPrice);
        return ApiResult.ok(orderDetails);
    }
}
